import Page
from Page import Launcher
from Base.Base import Base
from selenium.webdriver.common.by import By


class LauncherServiceSearchPage(Base):
    """
    桌面服务搜索页面
    """

    def __init__(self, driver):
        Base.__init__(self, driver)

        # 搜索框
        self.service_search_search_input = (By.XPATH, Launcher.RESOURCE_ID.format("et_normal_content"))

        # 搜索列表
        self.service_search_list_title_text = (By.XPATH, Launcher.service_search_list_title_text.format(1))

    def input_search(self, text):
        """
        输入框输入内容

        :param text: 搜索内容
        :return:
        """
        self.input_text(self.service_search_search_input, text)

    def get_list_title(self, index=1):
        """
        根据索引获取搜索结果列表的标题

        :param index: 索引值, 默认取1
        :return:
        """
        self.service_search_list_title_text = (By.XPATH, Launcher.service_search_list_title_text.format(index))
        return self.find_element_o(self.service_search_list_title_text)
